package com.sunyur.tailor.channel.service.outer.org.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sunyur.tailor.channel.common.middle.base.ChannelListResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;
import com.sunyur.tailor.channel.common.middle.util.ChannelListResultUtil;
import com.sunyur.tailor.channel.common.middle.util.RestTemplateUtil;
import com.sunyur.tailor.channel.service.outer.org.model.OuterOrgModel;
import com.sunyur.tailor.channel.service.outer.org.param.OuterOrgParam;
import com.sunyur.tailor.channel.service.outer.org.service.OuterOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Objects;

/**
 *
 * @Author 99288
 * @Description 外部组织实现类
 * @Date 22:32 2021/7/7
 * @Param
 * @return
**/
@Slf4j
@Service("outerOrgService")
public class OuterOrgServiceImpl implements OuterOrgService {

    @Value("${outer.oa.org}")
    private String orgUrl;

    @Autowired
    private RestTemplateUtil restTemplateUtil;

    @Override
    public ChannelListResult<OuterOrgModel> getOrgList(OuterOrgParam outerOrgParam) {
        log.info("get outer org param:{}", JSON.toJSONString(outerOrgParam));
        if (Objects.isNull(outerOrgParam)) {
            return ChannelListResultUtil.error(MiddleResultEnum.PARAM_NULL.getCode(), MiddleResultEnum.PARAM_NULL.getValue());
        }
        JSONObject jsonObject = restTemplateUtil.exchangeFormUrlencodedPost(outerOrgParam, orgUrl);
        if(Objects.nonNull(jsonObject)){

        }
        return ChannelListResultUtil.error(MiddleResultEnum.FAILED.getCode(), MiddleResultEnum.FAILED.getValue());
    }
}
